import {message} from 'antd';
import {formatMessage} from './intl';

export const updateValidator = data => {
    const dealerServiceInformation = data.dealerServiceInformation;
    const partPriceCoefficientDetail = data.partPriceCoefficientDetail;
    if(dealerServiceInformation.some(d => !d.brandId)) {
        message.warning(formatMessage({
            id: 'validator.message.brandId',
            defaultMessage: '品牌'
        }));
        return false;
    }
    if(dealerServiceInformation.some(d => !d.currency)) {
        message.warning(formatMessage({
            id: 'validator.message.currency',
            defaultMessage: '币种'
        }));
        return false;
    }
    if(dealerServiceInformation.some(d => !d.exAuthorizatedLimit)) {
        message.warning(formatMessage({
            id: 'validator.message.exAuthorizatedLimit',
            defaultMessage: '备件超授权额度'
        }));
        return false;
    }
    if(dealerServiceInformation.some(d => !d.price)) {
        message.warning(formatMessage({
            id: 'validator.message.price',
            defaultMessage: '工时单价'
        }));
        return false;
    }
    if(dealerServiceInformation.some(d => !d.mgmtFeeRate)) {
        message.warning(formatMessage({
            id: 'validator.message.mgmtFeeRate',
            defaultMessage: '备件管理费率'
        }));
        return false;
    }
    if(partPriceCoefficientDetail.some(d => !d.brandId)) {
        message.warning(formatMessage({
            id: 'validator.message.brandId',
            defaultMessage: '品牌'
        }));
        return false;
    }
    if(partPriceCoefficientDetail.some(d => !d.priceRate)) {
        message.warning(formatMessage({
            id: 'validator.message.priceRate',
            defaultMessage: '价格系数'
        }));
        return false;
    }
    return true;
};

